//
//  ScoreResultTableViewCell.m
//  LiveSoftware
//
//  Created by lanou3g on 15/7/25.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "ScoreResultTableViewCell.h"

#import "ScoreModel.h"



@interface ScoreResultTableViewCell ()

@property(nonatomic,strong)UIView *leftView;
@property(nonatomic,strong)UIView *middleView;
@property(nonatomic,strong)UIView *rightView;

// 比分视图
@property(nonatomic,strong)UIView *scoreView;




//联赛颜色
@property(nonatomic,strong)UILabel *leagueColorLabel;

//联赛名字
@property(nonatomic,strong)UILabel *leagueNameLabel;


//主队排名
@property(nonatomic,strong)UILabel *homeRankLabel;

//主队名字
@property(nonatomic,strong)UILabel *homeNameLabel;

//主队黄牌
@property(nonatomic,strong)UILabel *homeYellowCardLabel;
//主队红牌
@property(nonatomic,strong)UILabel *homeRedCardLabel;

@property(nonatomic,strong)UIImageView *homeYellowCard;
@property(nonatomic,strong)UIImageView *homeRedCard;



//客队排名
@property(nonatomic,strong)UILabel *awayRankLabel;

//客队名字
@property(nonatomic,strong)UILabel *awayNameLabel;

//客队黄牌
@property(nonatomic,strong)UILabel *awayYellowLabel;
//客队红牌
@property(nonatomic,strong)UILabel *awayRedLabel;

@property(nonatomic,strong)UIImageView *awayYellowCard;
@property(nonatomic,strong)UIImageView *awayRedCard;



/**
 *  比赛状态
 0  表示未开赛
 1  表示上半场
 2  表示中场
 3  表示下半场
 -1  表示已结束
 */
@property(nonatomic,strong)UILabel *matchStateLabel;


// 开始时间
@property(nonatomic,strong)UILabel *startTime;




//主队全场比分
@property(nonatomic,strong)UILabel *homeWholeGoalsLabel;


//客队全场比分
@property(nonatomic,strong)UILabel *awayWholeGoalsLabel;


// 冒号
@property(nonatomic,strong)UIImageView *maohao;


// 半场比分
@property(nonatomic,strong)UILabel *halfGoals;




@end


@implementation ScoreResultTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        CGFloat middleWidth = kScreenIp6(100);
        CGFloat leftWidth = (kScreenWidth - kScreenIp6(100)) / 2;
        CGFloat rightWidth = leftWidth;
        
        self.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenIp6(10), leftWidth, kScreenIp6(65))];
        [self.contentView addSubview:_leftView];
        
        
        self.middleView = [[UIView alloc]initWithFrame:CGRectMake(leftWidth, kScreenIp6(10), middleWidth, kScreenIp6(65))];
        [self.contentView addSubview:_middleView];
        
        
        self.rightView = [[UIView alloc]initWithFrame:CGRectMake(leftWidth + middleWidth, kScreenIp6(10), rightWidth, kScreenIp6(65))];
        [self.contentView addSubview:_rightView];
        

        
#pragma mark - ===================== 左边视图 ======================
        
        
#pragma mark  比赛开始时间
        
        self.startTime = [[UILabel alloc] initWithFrame:CGRectMake(kScreenIp6(10), kScreenIp6(0), kScreenIp6(50), kScreenIp6(15))];
        self.startTime.font = [UIFont systemFontOfSize:12];
        self.startTime.textColor = [UIColor colorWithWhite:0.380 alpha:1.000];
        self.startTime.textAlignment = 1;
        [self.leftView addSubview:_startTime];
        
        
        
        
#pragma mark 联赛名字
        self.leagueNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, leftWidth, kScreenIp6(15))];
        
        self.leagueNameLabel.font = [UIFont systemFontOfSize:12];
        self.leagueNameLabel.textColor = [UIColor colorWithWhite:0.380 alpha:1.000];
        self.leagueNameLabel.textAlignment = 2;
        [self.leftView addSubview:_leagueNameLabel];
        
        
#pragma mark 主队名字
        self.homeNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(leftWidth - kScreenIp6(110), CGRectGetMaxY(self.leagueNameLabel.frame), kScreenIp6(110), kScreenIp6(30))];
        
        [self.leftView addSubview:_homeNameLabel];
        
        
        
#pragma mark 主队黄牌
        
        self.homeYellowCard = [[UIImageView alloc]initWithFrame:CGRectMake(leftWidth - kScreenIp6(13), CGRectGetMaxY(self.homeNameLabel.frame), kScreenIp6(13), kScreenIp6(15))];
        [self.leftView addSubview:_homeYellowCard];
        
        
        self.homeYellowCardLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.homeYellowCard.frame) - kScreenIp6(15), self.homeYellowCard.frame.origin.y, kScreenIp6(15), kScreenIp6(15))];
        self.homeYellowCardLabel.font = [UIFont systemFontOfSize:12];
        self.homeYellowCardLabel.textAlignment = 1;
        [self.leftView addSubview:_homeYellowCardLabel];
        
        
#pragma mark 主队红牌
        
        self.homeRedCard = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.homeYellowCardLabel.frame) - kScreenIp6(18), self.homeYellowCard.frame.origin.y, kScreenIp6(13), kScreenIp6(15))];
        [self.leftView addSubview:_homeRedCard];
        
        
        self.homeRedCardLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.homeRedCard.frame) - kScreenIp6(15), self.homeYellowCard.frame.origin.y, kScreenIp6(15), kScreenIp6(15))];
        self.homeRedCardLabel.font = [UIFont systemFontOfSize:12];
        self.homeRedCardLabel.textAlignment = 1;
        [self.leftView addSubview:_homeRedCardLabel];
        
        
        
        
        
        
        
#pragma mark - ===================== 右边视图 ========================
        
#pragma mark 比赛状态
        
        self.matchStateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenIp6(80), kScreenIp6(15))];
        
        self.matchStateLabel.font = [UIFont systemFontOfSize:12];
        self.matchStateLabel.textColor = [UIColor colorWithWhite:0.380 alpha:1.000];
        [self.rightView addSubview:_matchStateLabel];
        
        
        
        
#pragma mark 客队名字
        
        self.awayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.matchStateLabel.frame), kScreenIp6(115), kScreenIp6(30))];
        
        [self.rightView addSubview:_awayNameLabel];
        
        
        
        
#pragma mark 客队黄牌
        
        
        
        self.awayYellowCard = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.awayNameLabel.frame), kScreenIp6(13), kScreenIp6(15))];
        [self.rightView addSubview:_awayYellowCard];
        
        
        self.awayYellowLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenIp6(15), CGRectGetMaxY(self.awayNameLabel.frame), kScreenIp6(15), kScreenIp6(15))];
        
        self.awayYellowLabel.textAlignment = 1;
        self.awayYellowLabel.font = [UIFont systemFontOfSize:12];
        
        [self.rightView addSubview:_awayYellowLabel];
        
        
        
        
        
#pragma mark 客队红牌
        
        
        
        self.awayRedCard = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenIp6(35), CGRectGetMaxY(self.awayNameLabel.frame), kScreenIp6(13), kScreenIp6(15))];
        [self.rightView addSubview:_awayRedCard];
        
        
        self.awayRedLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenIp6(50), CGRectGetMaxY(self.awayNameLabel.frame), kScreenIp6(15), kScreenIp6(15))];
        
        self.awayRedLabel.textAlignment = 1;
        self.awayRedLabel.font = [UIFont systemFontOfSize:12];
        
        [self.rightView addSubview:_awayRedLabel];
        
        
        
        
#pragma mark - ===================== 中间视图 =======================
        
        self.scoreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.middleView.bounds.size.width, self.middleView.bounds.size.height)];
        [self.middleView addSubview:_scoreView];
        
#pragma mark  主队得分
        
        self.homeWholeGoalsLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenIp6(25), kScreenIp6(10), kScreenIp6(20), kScreenIp6(30))];
        self.homeWholeGoalsLabel.adjustsFontSizeToFitWidth = YES;
        self.homeWholeGoalsLabel.textAlignment = 1;
        self.homeWholeGoalsLabel.font = [UIFont fontWithName:@"DB LCD Temp" size:26];
        self.homeWholeGoalsLabel.textColor = [UIColor colorWithRed:0.299 green:0.717 blue:0.174 alpha:1.000];
        [self.scoreView addSubview:_homeWholeGoalsLabel];
        
        
#pragma mark 客队得分
        
        self.awayWholeGoalsLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenIp6(55), kScreenIp6(10), kScreenIp6(20), kScreenIp6(30))];
        self.awayWholeGoalsLabel.adjustsFontSizeToFitWidth = YES;
        self.awayWholeGoalsLabel.textAlignment = 1;
        self.awayWholeGoalsLabel.font = [UIFont fontWithName:@"DB LCD Temp" size:26];
        self.awayWholeGoalsLabel.textColor = [UIColor colorWithRed:0.299 green:0.717 blue:0.174 alpha:1.000];
        [self.scoreView addSubview:_awayWholeGoalsLabel];
        
        
        
#pragma mark  冒号(会闪)
        
        self.maohao = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenIp6(43), kScreenIp6(10), kScreenIp6(10), kScreenIp6(30))];
        
        [self.scoreView addSubview:_maohao];
        
        
#pragma mark 半场比分
        self.halfGoals = [[UILabel alloc] initWithFrame:CGRectMake(0, kScreenIp6(40), middleWidth, kScreenIp6(20))];
        self.halfGoals.textAlignment = NSTextAlignmentCenter;
        self.halfGoals.font = [UIFont systemFontOfSize:14];
        [self.scoreView addSubview:_halfGoals];
        
        
        
        
        
        //线
        UIView *footLineView = [[UIView  alloc]initWithFrame:CGRectMake( 0, kScreenIp6(74), kScreenWidth, 0.5)];
        
        footLineView.backgroundColor = [UIColor colorWithWhite:0.699 alpha:1.000];
        
        [self addSubview:footLineView];
        
        
        
        
    }
    
    return self;
    
}


-(void)setCellValue:(ScoreModel*)model
{
    
    CGFloat leftWidth = (kScreenWidth - kScreenIp6(100)) / 2;
    CGFloat rightWidth = leftWidth;
    
    
    
    //联赛名字
    self.leagueNameLabel.text = model.leagueName;
    
    
    //主队名字 分割字符串, 去除中立场标识@"(中)"
    self.homeNameLabel.text = [[model.homeName componentsSeparatedByString:@"("] firstObject];
    
    CGRect homeBounds = [self.homeNameLabel.text boundingRectWithSize:CGSizeMake(leftWidth, kScreenIp6(30)) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont boldSystemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    
    self.homeNameLabel.frame = CGRectMake(self.leftView.bounds.size.width - homeBounds.size.width, CGRectGetMaxY(self.leagueNameLabel.frame), homeBounds.size.width, kScreenIp6(30));
    self.homeNameLabel.font = [UIFont boldSystemFontOfSize:15];
    self.homeNameLabel.adjustsFontSizeToFitWidth = YES;
    
    
    
    
    // 客队名字
    self.awayNameLabel.text = model.awayName;
    
    CGRect awayBounds = [self.awayNameLabel.text boundingRectWithSize:CGSizeMake(rightWidth, kScreenIp6(30)) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont boldSystemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    
    self.awayNameLabel.frame = CGRectMake(0, CGRectGetMaxY(self.matchStateLabel.frame), awayBounds.size.width, kScreenIp6(30));
    self.awayNameLabel.font = [UIFont boldSystemFontOfSize:15];
    self.awayNameLabel.adjustsFontSizeToFitWidth = YES;
    
    
    
    
    
    

            
    self.matchStateLabel.text = @"已结束";
    self.scoreView.alpha = 0.6;
    
    NSMutableString *time = [[model.startTime substringWithRange:NSMakeRange(8, 4)] mutableCopy];
    [time insertString:@":" atIndex:2];
    self.startTime.text = time;
    
    // 主队进球数
    self.homeWholeGoalsLabel .text = model.homeWholeGoals;
    self.awayWholeGoalsLabel.text = model.awayWholeGoals;
    self.maohao.image = [UIImage imageNamed:@"colon_green@2x"];
    
    if (![model.homeHalfGoals isEqualToString:@""] && ![model.awayHalfGoals isEqualToString:@""])
    {
        // 半场比分
        self.halfGoals.text = [NSString stringWithFormat:@"( %@ : %@ )",model.homeHalfGoals,model.awayHalfGoals];
    }
    else
    {
        self.halfGoals.text = @"";
    }
    
    
    
    if (model.homeYellowCard.intValue != 0)
    {
        self.homeYellowCardLabel.text = model.homeYellowCard;
        self.homeYellowCard.image = [UIImage imageNamed:@"newYC@2x"];
    }
    else
    {
        self.homeYellowCardLabel.text = @"";
        self.homeYellowCard.image = [UIImage imageNamed:@""];
    }
    
    if (model.homeRedCard.intValue != 0)
    {
        self.homeRedCardLabel.text = model.homeRedCard;
        self.homeRedCard.image = [UIImage imageNamed:@"newRC@2x"];
    }
    else
    {
        self.homeRedCardLabel.text = @"";
        self.homeRedCard.image = [UIImage imageNamed:@""];
    }
    
    if (model.awayYellowCard.intValue != 0)
    {
        self.awayYellowLabel.text = model.awayYellowCard;
        self.awayYellowCard.image = [UIImage imageNamed:@"newYC@2x"];
    }
    else
    {
        self.awayYellowLabel.text = @"";
        self.awayYellowCard.image = [UIImage imageNamed:@""];
    }
    
    if (model.awayRedCard.intValue != 0)
    {
        self.awayRedLabel.text = model.awayRedCard;
        self.awayRedCard.image = [UIImage imageNamed:@"newRC@2x"];
    }
    else
    {
        self.awayRedLabel.text = @"";
        self.awayRedCard.image = [UIImage imageNamed:@""];
    }
    
    
    
    
}




@end
